package cwinsor.com.leaf_raking;

import java.util.Arrays;
import java.util.List;

public final class StartTime {

	private StartTime(String n) { name = n; } // private constructor

	private String name;

	public static final StartTime T_8_30 = new StartTime("8:30");
	public static final StartTime T_10_00 = new StartTime("10:00");
	public static final StartTime T_11_30 = new StartTime("11:30");
	public static final StartTime T_1_00 = new StartTime("1:00");
	public static final StartTime T_2_30 = new StartTime("2:30");
	public static final StartTime T_4_00 = new StartTime("4:00");

	public static final StartTime PM = new StartTime("PM");

	public static final List<StartTime> START_TIMES = Arrays.asList(
			T_8_30,
			T_10_00,
			T_11_30,
			T_1_00,
			T_2_30,
			T_4_00);

	public final String name() { return name; };

	/*
	 * debug
	 */
	private static String dM = "StartTime----";
	private static String dF = "StartTime---- ERROR ---- ";

	/*
	 * stringToShift
	 * converts string to Shift
	 */
	public static StartTime stringContainsStartTime(String theString) {
		return stringContainsStartTime(theString, true);
	}

	public static final StartTime stringContainsStartTime(String theString, boolean failIfNotFound) {
		if (theString.contains(T_8_30.name())) { return T_8_30; }
		if (theString.contains(T_10_00.name())) { return T_10_00; }
		if (theString.contains(T_11_30.name())) { return T_11_30; }
		if (theString.contains(T_1_00.name())) { return T_1_00; }
		if (theString.contains(T_2_30.name())) { return T_2_30; }
		if (theString.contains(T_4_00.name())) { return T_4_00; }
		// default
		if (failIfNotFound) {
		System.out.println(dF + "in stringContainsStartTime - cannot convert "
				+ theString 
				+ " to a StartTime");
		System.exit(1);
		}
		return null;
	}
}

